#ifndef UI_ELEMENT_H__
#define UI_ELEMENT_H__
#include "ProjectHeader.h"

class UIElement
{
public:
	UIElement();
	UIElement(UIStat_delegate UIManStatGetter);

	virtual bool Draw(std::vector<vertex> * VBOVec, const std::map<int, texCoord2f>& texMap, GLuint currentTex);			//Standard draw function args; draws the entire ui element
	virtual bool DrawForeground(std::vector<vertex> * VBOVec, const std::map<int, texCoord2f>& texMap, GLuint currentTex);	//Standerd draw function args; Only draws foreground (displays on elements)
	virtual bool DrawBackground(std::vector<vertex> * VBOVec, const std::map<int, texCoord2f>& texMap, GLuint currentTex);	//Standard draw function args; Only draws background (shouldn't change)
	//DrawForeground draws the element's display (slider, number, icon, etc), while
	//DrawBackground draws the element's background (which only changes if the element is resized or the background is changed)
	
	void SetStat(int UIManRegisteredStat);					//Sets the stat number to use to get the stat to display
	void SetUIManDelegate(UIStat_delegate UIManStatGetter);	//Sets the delegate to call with the stat number to get the stat to display
	void SetBackground(texCoord2f backgroundTexture);		//Sets the background texture of the element
	void SetSize(vertex2f size);							//Sets the size of the element (0-1 for size, in screen size units)
	void SetPos(vertex2f position);							//Sets the position of the element on screen (0 - 1 for both; 0,0 -> btm left, 1,1 -> top right)
	
	bool Drawable();	//True if the element is currently drawable; all the data required has been given (position, size, etc)


protected:

	void DrawRectangle(std::vector<vertex> * VBOVec, rectangle Rectangle, texCoord2f Texture, GLfloat Depth);
	rectangle CalculateRectangle(vertex2f position, vertex2f size);
	
	virtual bool StatValueHasChanged();	//Returns true if the stat value changed since last time we looked

	int				_registeredStat;	//Holds an int used to get the element's stat from the UI manager
	int				_lastStatValue;		//Holds a copy of the value of the stat last time we checked
	UIStat_delegate _UIManStatGetter;	//Holds a delegate to call to get the stat to display

	texCoord2f		_backgroundTexture;	//Holds the texture used for the background of the UI element

	vertex2f _size;		//Holds the size of the control in screen units (0-1 along each axis goes from left to right or bottom to top)
	rectangle _area;	//Holds the position of all four corners of the element

	bool _fgDirty;				//True if the foreground needs redrawn; only applicable to inheritors of this class with displays
	bool _bgDirty;				//True if the background needs redrawn; for example, if the size, position or background is changed

	private:
	void SetAreaRectangle(vertex2f position);
};

#endif